package com.fmdj.cst.controller;
import cn.hutool.core.bean.BeanUtil;
import com.fmdj.common.util.CommonResult;
import com.fmdj.cst.controller.form.DeleteCustomerCarByIdForm;
import com.fmdj.cst.controller.form.InsertCustomerCarForm;
import com.fmdj.cst.controller.form.SelectCustomerCarListForm;
import com.fmdj.cst.db.pojo.CustomerCarEntity;
import com.fmdj.cst.service.CustomerCarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;

@RestController
@RequestMapping("/customer/car")
@Tag(name = "CustomerCarController", description = "客户车辆Web接口")
public class CustomerCarController {

    @Autowired
    private CustomerCarService customerCarService;

    @PostMapping("/insertCustomerCar")
    @Operation(summary = "添加车辆")
    public CommonResult insert(@Valid @RequestBody CustomerCarEntity entity) {
        int rows = customerCarService.insert(entity);
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }

    @PostMapping("/selectCustomerCarList")
    @Operation(summary = "查询客户车辆列表")
    public CommonResult selectCustomerCarList(@Valid @RequestBody SelectCustomerCarListForm form) {
        ArrayList<HashMap> result = customerCarService.selectCarList(form.getCustomerId());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, result);
    }

    @PostMapping("/deleteCustomerCarById")
    @Operation(summary = "删除车辆信息")
    public CommonResult deleteCustomerCarById(@Valid @RequestBody DeleteCustomerCarByIdForm form) {
        int rows = customerCarService.deleteCustomerCarById(form.getId());
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }
}
